package com.xy.user.service;

import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import com.xy.user.domain.Xypermission;
import com.xy.user.persistence.XypermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;




/**
 * 菜单角色权限关系
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class XypermissionService extends BaseService<Xypermission> {
    @Autowired
    private XypermissionMapper xypermissionMapper;

    @Autowired
    public void setBaseMapper(XypermissionMapper xypermissionMapper) {
        this.baseMapper = xypermissionMapper;
    }

    public List<Map<String,Object>> getListMenuId(Map<String, Object> param) {
        return xypermissionMapper.listMenuId(param);
    }
    public List<Map<String,Object>> getListRoleId(Map<String, Object> param) {
        return xypermissionMapper.listRoleId(param);
    }

    public void checkEntity(Xypermission xypermission) throws ClassCheckException {
        if(xypermission.getPermissionId()!=null&&xypermission.getPermissionId().length()>19){
            throw new ClassCheckException("菜单角色权限关系权限ID不能超过19个字符");
        }
        if(xypermission.getMenuId()!=null&&xypermission.getMenuId().length()>19){
            throw new ClassCheckException("菜单角色权限关系菜单不能超过19个字符");
        }
        if(xypermission.getRoleId()!=null&&xypermission.getRoleId().length()>19){
            throw new ClassCheckException("菜单角色权限关系角色不能超过19个字符");
        }
    }
    public void checkListEntity(List<Xypermission> listXypermission) throws ClassCheckException {

        for (Xypermission xypermission : listXypermission) {
            checkEntity(xypermission);
        }

    }

    public List<Map<String,Object>> AllMenuPermissionByRoleId(String roleId) {
        return xypermissionMapper.AllMenuPermissionByRoleId(roleId);
    }

    public List<Xypermission> queryByRoleId(String roleId) {
        return xypermissionMapper.queryByRoleId(roleId);
    }

}
